package org.lds.logger.config.appender.async.disruptor;

import com.lmax.disruptor.RingBuffer;
import org.lds.logger.event.LoggerEvent;

public class LoggerEventProducer {
    public final RingBuffer<LoggerEvent> ringBuffer;

    public LoggerEventProducer(RingBuffer<LoggerEvent> ringBuffer) {
        this.ringBuffer = ringBuffer;
    }

    public void send(LoggerEvent event) {
        long sequence = ringBuffer.next();
        try {
            LoggerEvent loggerEvent = ringBuffer.get(sequence);
            loggerEvent.setName(event.getName());
            loggerEvent.setLevel(event.getLevel());
            loggerEvent.setMessage(event.getMessage());
        } finally {
            ringBuffer.publish(sequence);
        }
    }
}
